﻿// ==============================================================================
// Created by Bndy at 05 / 21 / 2008
// Copyright (c) 2008 Bndy, All rights reserved.
// Welcome to my site http : // www.bndy.net
//
//                    * * * * * * * * * * * * * 
//                    * MAIL- bndy5337@163.com *       http://www.bndy.net
//                    * Q Q - 81795705 =========================================>
//                    * MSN - bndy5337@msn.com *
//                    * * * * * * * * * * * * * 
//
// ------------------------------------------------------------------------------
//
// ==============================================================================

/************************************ 数组处理 *********************************/
Array.prototype.clear = function () {
    while (this.length > 0) {
        this.pop();
    }
}

Array.prototype.addItem = function (item) {
    var i = this.length;
    this[i] = item;
    return i;
}

Array.prototype.indexOf = function (item) {
    var index = -1;
    for (var i = 0; i < this.length; i++) {
        if (this[i] == item) {
            index = i;
            break;
        }
    }

    return index;
}
/************************************ 数组处理 *********************************/

var CheckTpe = new ValidateTypeList();

function ValidateTypeList(){
    this.CheckInt = "Int";
    this.CheckEmpty = "Empty";
    this.CheckDate = "Date";
    this.CheckEqual = "Equal";
    this.CheckFloat = "Float";
}

/************************************ 元素操作 *********************************/

function $_(eleID){
    var obj = document.getElementById(eleID);
    if (obj == null) {
        return null;
        alert("未能获取对象" + eleID);
    }
    
    return obj;
}

function $__(eleName){
    var objs = document.getElementsByName(eleName);
    if (objs.length <= 0) {
        return null;
        alert("未能获取对象" + eleName);
    }
    
    return objs;
}

function getValueById(eleID){
    var obj = $_(eleID);
    var result = '';
    
    if (obj != null) {
        result = obj.value;
    }
    
    return result;
}

function getInnerHtmlById(eleID){
    var obj = $_(eleID);
    if (obj != null) {
        return obj.innerHTML;
    }
    
    return '';
}

function setInnerHTMLById(eleID, html){
    var obj = $_(eleID);
    if (obj != null) {
        obj.innerHTML = html;
    }
}





/************************************ 元素操作 *********************************/


/************************************ XML操作 **********************************/

function getXml(path){
    if (window.DOMParser) //firefox内核的浏览器
    {
        var p = new DOMParser();
        return p.parseFromString(path, "text/xml");
    }
    else 
        if (window.ActiveXObject) //ie内核的浏览器
        {
            var doc = new ActiveXObject("Msxml2.DOMDocument");
            doc.loadXML(path);
            return doc;
        }
}

function createHtmlElement(tagName, type, id, value, className, style){
    var ele = document.createElement(tagName);
    if (id != null) {
        ele.setAttribute('id', id);
    }
    if (type != null) {
        ele.setAttribute('type', type);
    }
    if (value != null) {
        ele.setAttribute('value', value);
    }
    if (className != null) {
        ele.setAttribute('class', className);
        ele.setAttribute('className', className);
    }
    if (style != null) {
        ele.setAttribute('style', style);
        ele.style.cssText = style;
    }
    
    return ele;
}

function getNodeValueByIdTagname(tagName, xmlDoc){
    var result = xmlDoc.getElementsByTagName(tagName)[0].childNodes[0].nodeValue;
    return result;
}

function clearChildren(eleID){
    var obj = $_(eleID);
    if (obj != null) {
        while (obj.childNodes.length > 0) {
            obj.removeChild(obj.childNodes[0]);
        }
    }
}

/************************************ XML操作 **********************************/


/*********************************** 过滤层 ************************************/
function buildGlobalLayer() {
	window.bdscrollHeight = document.body.scrollHeight || document.documentElement.scrollHeight;
	if ( browser.msie && browser.version != '7.0' ) {//IE 7.0 iframe
		var gIfr			= document.createElement( 'iframe' );
		gIfr.id				='globalIfr';
		gIfr.style.display	= 'none';
		gIfr.style.position	= 'absolute';
		gIfr.style.clear	= 'both';
		gIfr.style.zIndex	= '90';
		gIfr.style.left		= '0px';
		gIfr.style.top		= '0px';
		gIfr.style.width	= '0px';
		gIfr.style.height	= '0px';
		gIfr.style.border	= '0px #ffffff solid';
		gIfr.onselectstart	= function() { return false;};
		gIfr.style.filter	= 'alpha(opacity=0)';
		document.body.appendChild( gIfr );
	}
	var gDiv				= document.createElement( 'div' );
	gDiv.id					= 'globalDiv';
	gDiv.style.display		= 'none';
	gDiv.style.position		= 'absolute';
	gDiv.style.clear		= 'both';
	gDiv.style.zIndex		= '91';
	gDiv.style.left			= '0px';
	gDiv.style.top			= '0px';
	gDiv.style.width		= '0px';
	gDiv.style.height		= '0px';
	gDiv.style.border		= '0px #ffffff solid';
	gDiv.style.background	= 'darkgray';
	gDiv.onselectstart		= function() { return false;};
	if ( browser.msie ) {
		gDiv.style.filter	= 'alpha(opacity=30)';
	}
	else {
		gDiv.style.opacity	= 30/100;
	}
	document.body.appendChild( gDiv );
}

//打开过滤层
function openGlobalLayer() {
    
    buildGlobalLayer();
    
	window.bdscrollHeight = document.body.scrollHeight || document.documentElement.scrollHeight;
	var bw = ( document.body.clientWidth || document.documentElement.scrollWidth ) + 'px';
	var bh = ( document.body.clientHeight || document.body.scrollHeight || document.documentElement.scrollHeight ) + 'px';
	if ( $_( 'globalIfr' ) != null) {
		$_( 'globalIfr' ).style.width	= bw;
		$_( 'globalIfr' ).style.height	= bh;
		$_( 'globalIfr' ).style.display = 'block';
	}
	$_( 'globalDiv' ).style.width		= bw;
	$_( 'globalDiv' ).style.height		= bh;
	$_( 'globalDiv' ).style.display		= 'block';

}

//关闭过滤层
function closeGlobalLayer() {
	if ( $_("globalIfr") ) {
		$_( 'globalIfr' ).style.width	= '0px';
		$_( 'globalIfr' ).style.height	= '0px';
		$_("globalIfr").style.display	= 'none';
	}
	$_( 'globalDiv' ).style.width		= '0px';
	$_( 'globalDiv' ).style.height		= '0px';
	$_( 'globalDiv' ).style.display		= 'none';
}

/*********************************** 过滤层 ************************************/   

/********************************* 窗口和对话框操作 *****************************/

function openWindow(url, wid, hei){
    var iTop = (window.screen.height - hei) / 2;
    var iLeft = (window.screen.width - wid) / 2;
    
    window.open(url, '', 'width=' + wid + ',height=' + hei + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
}

function showDialog(url, wid, hei){
    var iTop = (window.screen.height - hei) / 2;
    var iLeft = (window.screen.width - wid) / 2;
    
    if (url.indexOf('?') > 0) {
        url = url + '&' + (new Date()).getTime();
    }
    else {
        url = url + '?' + (new Date()).getTime();
    }
    
    alert(url);
    
    window.showModalDialog(url, window, 'dialogHeight:' + hei + 'px; dialogWidth:' + wid + 'px; dialogTop:' + iTop + ';dialogLeft:' + iLeft + ';resizable:no; status:no; scroll:no; help:no; center:yes; dge:raised;');
}

function submitForm(){
    document.forms[0].submit();
}

function showMessageBox(msg, ok, cancel, okMethod, cancelMethod){

    openGlobalLayer();
    
    var boxWidth = 200;
    var iTop = (window.screen.height - boxWidth) / 2;
    var iLeft = (window.screen.width - 200) / 2;
    // 样式声明
    var cMainStyle = 'width:' + boxWidth + 'px; height:150px; border:solid 1px #7998b7; background:#ecf4fb; position:absolute; z-index:1000;';
    
    var cHeaderStyle = 'both:clear; padding:5px 5px; background:#3277c7;vertical-align:middle;';
    var cTitleStyle = 'font-weight:bold; color:#FFFFFF; float:left;';
    var cCloseStyle = 'vertical-align:middle; float:right';
    
    var cMsgStyle = 'height:80px; line-height:80px; text-align:center; border:solid 1px #d7e0e7; background:#F8F8F8;';
    
    var cFooterStyle = 'float:right; height:30px; padding:5px;';
    
    // 主对话框
    var cMain = document.createElement('div');
    var cMainID = 'msgBoxDiv' + Math.random(); // 对话框ID
    cMain.setAttribute('id', cMainID);
    cMain.setAttribute('style', cMainStyle);
    cMain.style.cssText = cMainStyle;
    document.body.appendChild(cMain);
    positCenter(cMainID);
    
    // 生成头部代码
    var cHeader = document.createElement('div');
    var cTitle = document.createElement('div');
    var cClose = document.createElement('div');
    cHeader.setAttribute('style', cHeaderStyle);
    cTitle.setAttribute('style', cTitleStyle);
    cClose.setAttribute('style', cCloseStyle);
    cHeader.style.cssText = cHeaderStyle;
    cTitle.style.cssText = cTitleStyle;
    cClose.style.cssText = cCloseStyle;
    cClose.setAttribute('onclick', 'hiddenElement("' + cMainID + '");');
    cTitle.innerHTML = '<img src="image/info.gif" style="vertical-align:middle;" /> 系统提示';
    cClose.innerHTML = '<img src="image/close.gif" style="vertical-align:middle;"  onmouseover=this.src="image/close1.gif"; onmouseout=this.src="image/close.gif"; onclick="hiddenElement(\'' + cMainID + '\');" alt="关闭" />';
    cHeader.appendChild(cTitle);
    cHeader.appendChild(cClose);
    
    cMain.appendChild(cHeader);
    
    // 生成正文代码
    var cMsg = document.createElement('div');
    cMsg.setAttribute('style', cMsgStyle);
    cMsg.style.cssText = cMsgStyle;
    cMsg.innerHTML = msg;
    
    cMain.appendChild(cMsg);
    
    // 生成底部代码
    var cFooter = document.createElement('div');
    cFooter.setAttribute('style', cFooterStyle)
    cFooter.style.cssText = cFooterStyle;
    if (ok) {
        //var btnOK = createHtmlElement('input', 'button', 'btnOK', null, null);
        //btnOK.setAttribute('value', '确定');
        //btnOK.setAttribute('onClick', (okMethod == null ? '' : okMethod) + 'hiddenElement("' + cMainID + '");');
        //cFooter.appendChild(btnOK);
        
        var btnOKStr = '<input type="button" value="确定" onclick="' + (okMethod == null ? '' : okMethod) + ' hiddenElement(\'' + cMainID + '\');closeGlobalLayer();" />';
        cFooter.innerHTML = btnOKStr;
    }
    if (cancel) {
        //var btnCancel = createHtmlElement('input', 'button', 'btnCancel', null, null);
        //btnCancel.setAttribute('value', '取消');
        //btnCancel.setAttribute('onclick', (cancelMethod == null ? '' : cancelMethod) + 'hiddenElement(\'' + cMainID + '\');');
        //cFooter.appendChild(btnCancel);
        
        var btnCancelStr = '<input type="button" value="取消" onclick="' + (cancelMethod == null ? '' : cancelMethod) + ' hiddenElement(\'' + cMainID + '\'); closeGlobalLayer();" />';
        cFooter.innerHTML += btnCancelStr;
    }
    
    cMain.appendChild(cFooter);
    
    return cMain;
}

/********************************* 窗口和对话框操作 *****************************/